<?php
class SyllabusController extends Zend_Controller_Action{
	public function indexAction(){
		$auth = Zend_Auth::getInstance();
		$params = $this->_getAllParams();
		if(isset($params['annee'])&&isset($params['section'])&&!empty($params['section'])&&!empty($params['annee'])){
			$annee = (int) htmlentities($params['annee']);
			$section = (int) htmlentities($params['section']);
		}else if($auth->hasIdentity()){
			$annee = $auth->getIdentity()->annee;
			$section = $auth->getIdentity()->section_id; 
		}else{
			$this->_helper->redirector('search','syllabus');
		}
		$mapper = new Application_Model_SyllabusMapper();
		$this->view->entries = $mapper->fetchByGroup($annee, $section);
	}
	public function searchAction(){
		$request = $this->getRequest();
		$form = new Application_Form_Syllabus($this->_helper->Section->getSectArray());
		$this->_helper->Security->removeCaptcha($form);
		if($request->isPost()){
			if($form->isValid($request->getPost())){
				$values = $form->getValues();
				$this->_helper->redirector('index','syllabus',null,$values);
			}else{
				$this->view->form = $form;
			}
		}else{
			$this->view->form = $form;
		}
	}
}